//
//  SHMarketViewController.swift
//  RxSwiftDemo2019_03_31
//
//  Created by bebull on 2021/12/27.
//  Copyright © 2021 远平. All rights reserved.
//

import UIKit

class SHMarketViewController: UIViewController {
    
    private lazy var tabLayout: YXTabLayout = {
        let layout = YXTabLayout.default()
        layout.titleColor = UIColor.qmui_color(withHexString: "#878D9A") ?? .red
        layout.titleSelectedColor = UIColor.qmui_color(withHexString: "#1D252C") ?? .red
        layout.titleFont = UIFont.systemFont(ofSize: 16)
        layout.titleSelectedFont = UIFont.systemFont(ofSize: 16, weight: .semibold)
        
        layout.tabWidth = 50.0
        layout.leftAlign = true
        layout.lrMargin = 0
        layout.tabMargin = 0
        layout.lineColor = .clear
        return layout
    }()
    
    lazy var tabView: YXTabView = {
        let tabView = YXTabView(frame: CGRect(x: 0, y: 0, width: view.bounds.size.width, height: kTabHeight), with: self.tabLayout)
        tabView.backgroundColor = .white
        tabView.delegate = self as YXTabViewDelegate
        tabView.layer.borderWidth = 0
        tabView.titles = ["港股", "美股"]
        tabView.pageView = self.pageView
        return tabView
    }()
    
    
    private lazy var pageView: YXPageView = {
        let view = YXPageView()
        view.contentView.isScrollEnabled = true
        view.parentViewController = self
        view.backgroundColor = .clear
        view.contentView.backgroundColor = .clear
        view.viewControllers = [SHHKMarketDetailViewController(), SHUSMarketDetailViewController()]
        return view
    }()
    
    private let kTabHeight: CGFloat = 48

    override func viewDidLoad() {
        super.viewDidLoad()

        view.backgroundColor = .brown
        
        view.addSubview(tabView)
        view.addSubview(pageView)
        pageView.snp.makeConstraints { make in
            make.left.right.bottom.equalToSuperview()
            make.top.equalToSuperview().offset(kTabHeight)
        }
    }

}

extension SHMarketViewController: YXTabViewDelegate {
    
    func tabView(_ tabView: YXTabView, didSelectedItemAt index: UInt, withScrolling scrolling: Bool) {
        ///
    }
    
}
